package tcp.demo;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import lombok.SneakyThrows;

/**
 * @author zss
 * @date 2021/8/31 14:15
 * @Email:451682479@qq.com
 */
public class ServerThread extends Thread {

    public ServerThread(Socket accept) {
        this.socket = accept;
    }

    private Socket socket;

    @SneakyThrows
    @Override
    public void run() {

        InputStream inputStream = socket.getInputStream();

        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader reader = new BufferedReader(inputStreamReader);

        String info;
        while ((info = reader.readLine()) != null) {
            long id = Thread.currentThread().getId();
            System.out.println("服务端输出。。。" + info + " threadId = " + id);
        }

        socket.shutdownInput();

    }
}
